package dotcom;


import java.io.*;
import java.util.*;


public class gamehelper {
	

	private static final String alphabet = "abcdefg";
	private int gridlength = 7;
	private int gridsize = 49;
	private int[] grid = new int[gridsize];
	private int comcount = 0;
	
	
	
	public String getuserinput(String prompt)
	{
		String inputline	= null;
		System.out.print(prompt + "");
		
		try
		{
			BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
			inputline = is.readLine();
			
			if(inputline.length() == 0)
				return null;
			
		} catch(IOException e) {
			
			System.out.println("OExeption : " +  e);
			
		}
		return inputline.toLowerCase();
	}
	
	
	
	public ArrayList<String> placedotcom(int comsize)
	{
		ArrayList<String> alphacells = new ArrayList<String>();
		String	temp = null;
		int[] coords = new int[comsize];
		int attempts = 0;
		boolean success = false;
		int location = 0;
		
		comcount++;
		
		int incr = 1;
		if((comcount%2) == 1){
			incr = gridlength;
		}
		
		
		while(!success&attempts++ <200){
			
			location = (int)(Math.random()*gridsize);
			
			int x = 0;
			
			success = true;
			while(success&& x < comsize)
			{
				if(grid[location] == 0)
				{
					coords[x++] = location;
					location += incr;
					
					if(location >= gridsize)
					{
						success = false;
					}
					
					if(x>0 & (location%gridlength == 0))
					{
						success = false;
					}
					else
					{
						success = false;
					}
				}
			}
		}
		
		int x = 0;
		int row = 0;
		int column = 0;
		
		while(x<comsize)
		{
			grid[coords[x]] = 1;
			row = (int)(coords[x]/gridlength);
			column = coords[x]%gridlength;
			temp = String.valueOf(alphabet.charAt(column));
			
			alphacells.add(temp.concat(Integer.toString(row)));
			x++;
		}
		
		
		return alphacells;
	}
	
}
